<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>数据库比对
    </title>
    <link type="text/css" rel="stylesheet" th:href="@{${skinPath} + '/css.css'}"/>
    <style type="text/css">
        body {
            margin-top: 0px;
            margin-bottom: 0px;
        }

        body, td, th {
            font-size: 14px;
        }
    </style>
    <link href="index.css" rel="stylesheet" type="text/css">
    <script th:src="@{/inc/common.js}"></script>
    <script th:src="@{/js/jquery-3.7.1.min.js}"></script>
    <script th:src="@{/js/jquery-alerts/cws.alerts.js}" type="text/javascript"></script>
    <link th:href="@{/js/jquery-alerts/jquery.alerts.css}" rel="stylesheet" type="text/css" media="screen"/>
    <link th:href="@{/js/jquery-showLoading/showLoading.css}" rel="stylesheet" media="screen"/>
    <script type="text/javascript" th:src="@{/js/jquery-showLoading/jquery.showLoading.js}"></script>
    <script th:src="@{/js/layui/layui.js}" charset="utf-8"></script>
    <link rel="stylesheet" th:href="@{/js/layui/css/layui.css}" media="all">
</head>
<body>
<div style="text-align:center;margin:20px">
    <input type="button" value="上一步" class="btn btn-default" onclick="window.location.href='tools'"/>&nbsp;&nbsp;
    <strong>请选择对应其它系统的数据源</strong>
    <select id="dbSource" name="dbSource">
        <option value="">请选择</option>
        <option th:each="di : ${diInfo}"
                th:value="${di.name}"
                th:selected="${di.isDefault}"
                th:text="${di.name}">
        </option>
    </select>
    <script th:inline="javascript">
        o('dbSource').value = [[${dbSource}]];
    </script>
    &nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;"
                               onclick="if ('oa'==$('#dbSource').val()) {alert('不能修改默认的数据源oa'); return;} openWin('dbConnEdit?dbSource=' + $('#dbSource').val(), 640, 480)">修改数据源</a>
    &nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="btn btn-default" value="数据差异"
                                   onclick="window.location.href='dbDiff?dbSource=' + o('dbSource').value;"/>
    &nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="btn btn-default" value="数据字典"
                                   onclick="window.location.href='dbDict?dbSource=' + o('dbSource').value;"/>
    <br/><br/>
    （以本系统数据库为新版，与其它旧版系统比较，可在脚本设计器中定义数据源指向其它系统，数据源的定义保存于proxool.xml中）
</div>

<script th:inline="javascript">
    $('#dbSource').val("[(${dbSource})]");
</script>
<th:block th:if="${dbSource != ''}">
    <div style="margin:20px">
        <form id="formCreateTable" method="post">
            <strong>增加的表:</strong><br>
            <span th:utext="${add_table}"></span>
            <br>
            <input name="op" type="hidden" value="createTableBatch"/>
            <input name="dbSource" type="hidden" th:value="${dbSource}"/>
            &nbsp;<input class="btn btn-default" id="btnCreateTableBatch" type="buttom" value="批量增加表"/><br/><br/>
        </form>
        <strong>删除的表:</strong><br>
        <span th:utext="${del_table}"></span>
        <br>
        <form id="formAddCol" method="post">
            <strong>增加的列:</strong><br>
            <span th:utext="${add_column}"></span>
            <input name="op" type="hidden" value="addColumnBatch"/>
            <input name="dbSource" type="hidden" th:value="${dbSource}"/>
            <br>
            &nbsp;<input class="btn btn-default" id="btnAddColumnBatch" type="button" value="批量增加列"/><br/><br/>
        </form>

        <strong>删除的列:</strong><br>
        <span th:utext="${del_column}"></span>
        <br>
        <form id="formAlterCol" method="post">
            <strong>修改的列:</strong><br>
            <span th:utext="${change_column}"></span>
            <input name="dbSource" type="hidden" th:value="${dbSource}"/>
            <input name="op" type="hidden" value="alterColumnBatch"/>
            <br>
            &nbsp;<input class="btn btn-default" id="btnAlterColumnBatch" type="button" value="批量修改列"/><br/><br/>
        </form>

        旧系统版本
        <select id="version" name="version">
            <option value="4">4</option>
            <option value="5">5</option>
        </select>
        &nbsp;<input type="button" class="btn btn-default" value="增加表单中的系统定义的列" onclick="alterFormTable()"/><br/>
        <div>以下为升级7.0版本及之前的数据库</div>
        <input type="button" class="btn btn-default" title="将本数据库中的表名form_table_改为ft_（用于升级7.0版及之前的数据库）" value="更改表名" onclick="alterTableName()"/><br/>
        <input type="button" class="btn btn-default" title="将本数据库中的模块事件及过滤条件中的form_table_改为ft_（用于升级7.0版及之前的数据库）" value="更改模块事件及过滤条件中表名" onclick="alterTableNameInModuleScript()"/><br/>
        <input type="button" class="btn btn-default" title="将本数据库中的流程事件中的form_table_改为ft_（用于升级7.0版及之前的数据库）" value="更改流程事件中表名" onclick="alterTableNameInFlowScript()"/><br/>
    </div>
    <script>
        function createTable(tableNew) {
            $.ajax({
                type: "post",
                url: "dbDiffDo",
                data: {
                    op: "createTable",
                    dbSource: $('#dbSource').val(),
                    tableName: tableNew
                },
                dataType: "json",
                beforeSend: function (XMLHttpRequest) {
                    $('body').showLoading();
                },
                success: function (res, status) {
                    layer.alert(res.msg, {
                        yes: function () {
                            // window.location.reload();
                        }
                    });
                },
                complete: function (XMLHttpRequest, status) {
                    $('body').hideLoading();
                },
                error: function () {
                    alert(XMLHttpRequest.responseText);
                }
            });
        }

        $('#btnCreateTableBatch').click(function (e) {
            e.preventDefault();

            var params = $("#formCreateTable").serialize();
            $.ajax({
                type: "post",
                url: "dbDiffDoBatch",
                data: params,
                dataType: "json",
                beforeSend: function (XMLHttpRequest) {
                    $('body').showLoading();
                },
                success: function (res, status) {
                    layer.alert(res.msg, {
                        yes: function () {
                            window.location.reload();
                        }
                    });
                },
                complete: function (XMLHttpRequest, status) {
                    $('body').hideLoading();
                },
                error: function () {
                    alert(XMLHttpRequest.responseText);
                }
            });
        });

        $('#btnAddColumnBatch').click(function (e) {
            e.preventDefault();

            var params = $("#formAddCol").serialize();
            $.ajax({
                type: "post",
                url: "dbDiffDoBatch",
                data: params,
                dataType: "json",
                beforeSend: function (XMLHttpRequest) {
                    $('body').showLoading();
                },
                success: function (res, status) {
                    layer.alert(res.msg, {
                        yes: function () {
                            window.location.reload();
                        }
                    });
                },
                complete: function (XMLHttpRequest, status) {
                    $('body').hideLoading();
                },
                error: function () {
                    alert(XMLHttpRequest.responseText);
                }
            });
        });

        $('#btnAlterColumnBatch').click(function (e) {
            e.preventDefault();

            var params = $("#formAlterCol").serialize();
            console.log('params', params);
            $.ajax({
                type: "post",
                url: "dbDiffDoBatch",
                data: params,
                dataType: "json",
                beforeSend: function (XMLHttpRequest) {
                    $('body').showLoading();
                },
                success: function (res, status) {
                    layer.alert(res.msg, {
                        yes: function () {
                            window.location.reload();
                        }
                    });
                },
                complete: function (XMLHttpRequest, status) {
                    $('body').hideLoading();
                },
                error: function () {
                    alert(XMLHttpRequest.responseText);
                }
            });
        });

        function alterFormTable() {
            $.ajax({
                type: "post",
                url: "dbDiffDo",
                data: {
                    op: "alterFormTable",
                    dbSource: $('#dbSource').val(),
                    version: $('#version').val()
                },
                dataType: "json",
                beforeSend: function (XMLHttpRequest) {
                    $('body').showLoading();
                },
                success: function (res, status) {
                    layer.alert(res.msg, {
                        yes: function () {
                            window.location.reload();
                        }
                    });
                },
                complete: function (XMLHttpRequest, status) {
                    $('body').hideLoading();
                },
                error: function () {
                    alert(XMLHttpRequest.responseText);
                }
            });
        }

        function addColumn(tableName, columnName, columnSize, nullable, columnDef, columnType) {
            var params = {
                op: "addColumn",
                dbSource: $('#dbSource').val(),
                tableName,
                columnName,
                columnSize,
                nullable,
                columnDef,
                columnType
            }
            $.ajax({
                type: "post",
                url: "dbDiffDo",
                data: params,
                dataType: "json",
                beforeSend: function (XMLHttpRequest) {
                    $('body').showLoading();
                },
                success: function (res, status) {
                    layer.alert(res.msg, {
                        yes: function () {
                            window.location.reload();
                        }
                    });
                },
                complete: function (XMLHttpRequest, status) {
                    $('body').hideLoading();
                },
                error: function () {
                    alert(XMLHttpRequest.responseText);
                }
            });
        }

        function alterColumn(tableName, columnName, columnSize, nullable, columnDef, columnType) {
            var params = {
                op: "alterColumn",
                dbSource: $('#dbSource').val(),
                tableName,
                columnName,
                columnSize,
                nullable,
                columnDef,
                columnType
            }
            $.ajax({
                type: "post",
                url: "dbDiffDo",
                data: params,
                dataType: "json",
                beforeSend: function (XMLHttpRequest) {
                    $('body').showLoading();
                },
                success: function (res, status) {
                    layer.alert(res.msg, {
                        yes: function () {
                            window.location.reload();
                        }
                    });
                },
                complete: function (XMLHttpRequest, status) {
                    $('body').hideLoading();
                },
                error: function () {
                    alert(XMLHttpRequest.responseText);
                }
            });
        }

        function alterTableName() {
            $.ajax({
                type: "post",
                url: "alterTableName",
                data: {
                    dbSource: $('#dbSource').val(),
                },
                dataType: "json",
                beforeSend: function (XMLHttpRequest) {
                    $('body').showLoading();
                },
                success: function (res, status) {
                    layer.alert(res.msg, {
                        yes: function () {
                            window.location.reload();
                        }
                    });
                },
                complete: function (XMLHttpRequest, status) {
                    $('body').hideLoading();
                },
                error: function () {
                    alert(XMLHttpRequest.responseText);
                }
            });
        }

        // 将本数据库中的模块事件及过滤条件中的form_table_改为ft_
        function alterTableNameInModuleScript() {
            $.ajax({
                type: "post",
                url: "alterTableNameInModuleScript",
                data: {
                },
                dataType: "json",
                beforeSend: function (XMLHttpRequest) {
                    $('body').showLoading();
                },
                success: function (res, status) {
                    layer.alert(res.msg, {
                        yes: function () {
                        }
                    });
                },
                complete: function (XMLHttpRequest, status) {
                    $('body').hideLoading();
                },
                error: function () {
                    alert(XMLHttpRequest.responseText);
                }
            });
        }

        // 将本数据库中的流程事件中的form_table_改为ft_
        function alterTableNameInFlowScript() {
            $.ajax({
                type: "post",
                url: "alterTableNameInFlowScript",
                data: {
                },
                dataType: "json",
                beforeSend: function (XMLHttpRequest) {
                    $('body').showLoading();
                },
                success: function (res, status) {
                    layer.alert(res.msg, {
                        yes: function () {
                        }
                    });
                },
                complete: function (XMLHttpRequest, status) {
                    $('body').hideLoading();
                },
                error: function () {
                    alert(XMLHttpRequest.responseText);
                }
            });
        }
    </script>
</th:block>
</body>
</html>
